fix: canonical DELETE scanner + key-only single-index delete (W1) - #371
Merged
Conversation
added 5 commits
September 3, 2026 20:18
… flush rewrite) Stap-0 profiling showed batch DELETE (ExecuteBatchSQL wraps every batch in a storage transaction) was NOT using the tombstone path: the rollback-safe deferral only counted _pendingLogicalDeletes, so db.Flush() still ran the #366 full-file CompactPendingDeletes rewrite (~0.5-0.7s; DELETE stuck at ~12-16K ops/s). - IStorage.BufferTombstoneForCommit (default no-op) + Storage implementation: buffered offsets per file, applied as in-place negative-prefix markers by ApplyBufferedTombstones() inside FlushBufferedAppendsAndOverwrites() (the commit path) AFTER buffered appends are on disk; rollback discards the buffer via ClearBufferedAppends(). - DeleteRecordsCore + the contiguous FW bulk path now buffer the deleted offsets when IsInTransaction instead of incrementing _pendingLogicalDeletes, so the flush-time full-file rewrite is off the batch-DELETE path entirely. - Regression: batch DELETE survives reopen even WITHOUT an explicit Flush after ExecuteBatchSQL (commit already tombstoned the rows). Measured (same machine, Release, comparative harness DELETE 10K of ~100K rows): SQL 0.82s/12K -> 0.24s/41K ops/s, Direct 0.63s/16K -> 0.17s/58K ops/s; --pk legacy 0.16s/62K, fixed-width 0.13s/78K ops/s. Full suite EXIT=0.
- IStorage.TombstoneRecords (default loops TombstoneRecord); Storage batches the in-place negative-prefix markers over one cached read handle and evicts each affected page-cache page once instead of once per row. - ApplyBufferedTombstones (commit path) and Table.TombstoneDeletedPositions (direct non-transactional deletes) route through the batch API; offsets that are not physical records (EOF/already-marked) are skipped safely.
…parse (B3) - TryParseDeleteForBatch now also returns the canonical WHERE column + raw literal; ExecuteBatchSQL groups (where, column, literal) instead of plain WHERE strings. - Table.DeleteMultipleKeys mirrors DeleteMultiple (contiguous-FW gate -> PK fast path -> hash fast path -> generic fallback) but resolves keys directly from the pre-parsed column/literal; the 'col = literal' string and the second TryParseSimpleWhereClause pass are built only when a generic fallback actually runs. - Non-canonical statements keep the string path (mixed tables rebuild on the rare path).
…index columns The structured batch DELETE path (DeleteMultipleKeys) now decodes a minimal row: BuildDeleteKeyColumns computes the needed columns (PK + every loaded hash-index column), and DeserializeDeleteKeyRow walks the legacy variable-length record skipping the unneeded columns' payload parsing entirely, building a 1-3 entry dictionary instead of a full row. DeleteRecordsCore performs the identical PK/hash lookups on that subset. Fixed-width layouts and corrupt rows fall back to the full DeserializeRowFromSpan. Measured (Release, comparative harness DELETE 10K of ~100K rows, median of 3): SQL ~39-42K and Direct ~57K ops/s — neutral within run noise on this small-row workload; the win shows on wider rows / long unindexed TEXT payloads where payload parsing and boxing are skipped. Full suite + 4 CI-filter suites EXIT=0.
D2 profiling (env-gated phase timers) showed TryScanCanonicalDml's DELETE branch never consumed the whitespace/WHERE keyword after the table name, so every canonical 'DELETE ... WHERE col = literal' fell back to the regex path - DeleteMultipleKeys/B1 were dead code in the benchmark harness. - Fix scanner: DELETE now consumes whitespace + WHERE + whitespace before the WHERE column; canonical batch deletes route through the structured DeleteMultipleKeys path. - Diagnostics: Database.CanonicalDeleteStatementsParsed counter + CanonicalBatchDelete_EngagesStructuredPath regression test. - W1: in DeleteMultipleKeys, when the table has no PK tree and exactly one registered hash index (no B-tree manager) whose key is the condition value, delete positions are recorded with the known key - no per-row engine.Read/decode. Profile attribution (DELETE 10K, docs): read+decode 62-82ms, commit markers ~50ms, core 23-56ms, index 5-10ms. Per-row read remains while the delete core must remove each auto-rowid PK entry - next lever is batch PK stale/lazy-rebuild. docs/performance/EXECUTION_PLAN_UPDATE_DELETE.md: combined execution plan + D2 findings.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Stack
perf/keyonly-delete(PR perf: key-only DELETE row decode (B1) #370) ← perf: batch tombstone writes (C4) + structured batch DELETE (B3) #369 ← perf: apply DELETE tombstones at COMMIT for transactional deletes (no flush rewrite) #368 ← perf: durable Columnar DELETE in-place via tombstone markers (no flush rewrite) #367 ← master.Inhoud
TryScanCanonicalDml's DELETE-tak consumente nooit de whitespace/hetWHERE-keyword na de tabelnaam → elke canoniekeDELETE ... WHERE col = literalviel terug op de regex-path. Gevolg:DeleteMultipleKeys+ B1 (perf: key-only DELETE row decode (B1) #370) waren dead code in de benchmark-harness (verklaart waarom perf: batch tombstone writes (C4) + structured batch DELETE (B3) #369/perf: key-only DELETE row decode (B1) #370 neutraal leken). Nu routeren canonieke batch-deletes door de structured path.Database.CanonicalDeleteStatementsParsed+ regressietestCanonicalBatchDelete_EngagesStructuredPath.DeleteMultipleKeys, wanneer de tabel geen PK-tree heeft en exact één geregistreerde hash-index (geen B-tree manager) waarvan de key de conditiewaarde is, worden posities met de bekende key verwijderd — géén per-rijengine.Read/decode.D2-attributie (env-gated fase-timers, DELETE 10K docs-tabel)
Grote vervolg-hefboom met deze cijfers: de per-rij read + per-rij
Index.Delete(auto-rowid-PK) vervangen door één batch PK stale/lazy-rebuild na een grote delete-batch.Validatie
SharpCoreDB.Tests(Debug) + Release/CI-filter op alle vier de suites: EXIT=0.